package game

import (
	"context"
	"github.com/jinzhu/copier"
	"go.uber.org/zap"
	"navi-mumbai/app/rpc/game/pb"

	"navi-mumbai/app/api/business/internal/svc"
	"navi-mumbai/app/api/business/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetGameListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetGameListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGameListLogic {
	return &GetGameListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetGameListLogic) GetGameList(req *types.GetGameListReq) (resp *types.GetGameListResp, err error) {
	var in pb.UserGetGameListReq
	in.ProviderId = req.ProviderId
	in.PageNo = req.PageNo
	in.PageSize = req.PageSize
	var rsp *pb.UserGetGameListResp
	rsp, err = l.svcCtx.GameUserRpc.UserGetGameList(l.ctx, &in)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, err
	}
	resp = &types.GetGameListResp{List: make([]*types.Game, 0)}
	_ = copier.Copy(resp, rsp)
	return
}
